<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<form class="layui-form" style="width: 80%;" id="auf">
    <div class="layui-form-item">
        <label class="layui-form-label">登陆邮箱</label>
        <div class="layui-input-block">
            <input type="text" id="eMail" name="email" class="layui-input"
                   lay-verify="email" placeholder="请输入邮箱" value="">
            <label><span style="color: red">(激活账号、找回密码必须！)</span></label>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">昵称</label>
        <div class="layui-input-block">
            <input type="text" id="nickname" class="layui-input"
                   lay-verify="required" placeholder="请输入昵称" name="nickname" value="">
            <!-- <label><span style="color: red">(谨慎设置，暂时不支持修改！)</span></label> -->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" id="password" class="layui-input"
                   lay-verify="pass" placeholder="请输入密码" name="password" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="password" class="layui-input"
                   lay-verify="repass" placeholder="请输入确认密码" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男" checked>
            <input type="radio" name="sex" value="0" title="女"> <input
                type="radio" name="sex" value="2" title="保密">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">出生日期</label>
        <div class="layui-input-block">
            <input type="text" id="birthday" class="layui-input"
                   name="birthday" lay-verify="required" placeholder="请输入出生日期" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" class="layui-input" lay-verify="required"
                   placeholder="请输入地址" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="phone" class="layui-input"
                   lay-verify="phone" placeholder="请输入手机号" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addUser">立即提交</button>
        </div>
    </div>
</form>
<script th:src="@{/src/layui.js}"></script>

<script>
        layui.use(['form','layer','laydate','jquery'],function () {
            var form = layui.form,
                laydate = layui.laydate,
                $ = layui.jquery,
                layer = layui.layer;

            laydate.render({
                    elem:'#birthday',
                    max:'new Date()',
                    trigger:'click'
                })
            //添加
            form.on('submit(addUser)',function (data) {
                //console.log(data);
                $.ajax({
                    url:'/user/saveUser',
                    type:'post',
                    data:data.field,
                    dataType:'json',
                    success:function (res) {
                        if(res.code == 200){
                            layer.msg('添加成功',{icon:1},function () {
                                parent.layer.closeAll("iframe");
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(res.message,{icon:5});
                        }
                    }
                })
                return false; //表单不提交，通过ajax的方式异步提交数据。
            })
        })



</script>


</body>
</html>